package moltencore.config;

import moltencore.game.CannonConfiguration;
import org.apache.log4j.Logger;
import moltencore.config.exception.ConfigValidationException;

public class Config {
	private static Logger logger = Logger.getLogger(Config.class);

	private static Config config;

	private String resourcePath;
	private Integer queryUdpPort;
	private Integer responseUdpPort;
	private Float cannonRotationUpdateFrequencySeconds;
	private Float cannonFireForce;
	private Float cannonPanningSpeed;
	private Float ordinaryBubbleProbability;
	private Float ghostBubbleProbability;
	private Float rainbowBubbleProbability;
	private Float blazingBubbleProbability;
	private Integer frameBreak;
	private Integer pushCount;

	private Config() {
	}

	public Integer getQueryUdpPort() {
		return queryUdpPort;
	}

	void setQueryUdpPort(Integer queryUdpPort) {
		this.queryUdpPort = queryUdpPort;
	}

	public Integer getResponseUdpPort() {
		return responseUdpPort;
	}

	void setResponseUdpPort(Integer responseUdpPort) {
		this.responseUdpPort = responseUdpPort;
	}

	public Float getCannonFireForce() {
		return cannonFireForce;
	}

	void setCannonFireForce(Float cannonFireForce) {
		this.cannonFireForce = cannonFireForce;
	}

	public Float getCannonPanningSpeed() {
		return cannonPanningSpeed;
	}

	void setCannonPanningSpeed(Float cannonPanningSpeed) {
		this.cannonPanningSpeed = cannonPanningSpeed;
	}

	public Float getCannonRotationUpdateFrequencySeconds() {
		return cannonRotationUpdateFrequencySeconds;
	}

	void setCannonRotationUpdateFrequencySeconds(Float cannonRotationUpdateFrequencySeconds) {
		this.cannonRotationUpdateFrequencySeconds = cannonRotationUpdateFrequencySeconds;
	}

	public Float getOrdinaryBubbleProbability() {
		return ordinaryBubbleProbability;
	}

	void setOrdinaryBubbleProbability(Float ordinaryBubbleProbability) {
		this.ordinaryBubbleProbability = ordinaryBubbleProbability;
	}

	public Float getGhostBubbleProbability() {
		return ghostBubbleProbability;
	}

	void setGhostBubbleProbability(Float ghostBubbleProbability) {
		this.ghostBubbleProbability = ghostBubbleProbability;
	}

	public Float getRainbowBubbleProbability() {
		return rainbowBubbleProbability;
	}

	void setRainbowBubbleProbability(Float rainbowBubbleProbability) {
		this.rainbowBubbleProbability = rainbowBubbleProbability;
	}

	public Float getBlazingBubbleProbability() {
		return blazingBubbleProbability;
	}

	void setBlazingBubbleProbability(Float blazingBubbleProbability) {
		this.blazingBubbleProbability = blazingBubbleProbability;
	}

	void setFrameBreak(Integer frameBreak) {
		this.frameBreak = frameBreak;
	}

	public Integer getFrameBreak() {
		return frameBreak;
	}

	public Integer getPushCount() {
		return pushCount;
	}

	void setPushCount(Integer pushCount) {
		this.pushCount = pushCount;
	}

	public String getResourcePath() {
		return resourcePath;
	}

	public String getLevelsPath() {
		return resourcePath +  "/graphics/levels";
	}

	void setResourcePath(String resourcePath) {
		this.resourcePath = resourcePath;
	}

	public void validate() throws ConfigValidationException {
		if(queryUdpPort == null) {
			throw new ConfigValidationException("Query udp port not specified");
		}
		if(responseUdpPort == null) {
			throw new ConfigValidationException("Response udp port not specified");
		}
		if(cannonRotationUpdateFrequencySeconds == null) {
			throw new ConfigValidationException("Cannon rotation update frequency not specified");
		}
		if(cannonPanningSpeed == null) {
			throw new ConfigValidationException("Cannon rotation speed not specified");
		}
		if(cannonFireForce == null) {
			throw new ConfigValidationException("Cannon fire force not specified");
		}
		if(ordinaryBubbleProbability == null) {
			throw new ConfigValidationException("Ordinary Bubble probability not specified");
		}
		if(ghostBubbleProbability == null) {
			throw new ConfigValidationException("Ghost Bubble probability not specified");
		}
		if(rainbowBubbleProbability == null) {
			throw new ConfigValidationException("Rainbow Bubble probability not specified");
		}
		if(blazingBubbleProbability == null) {
			throw new ConfigValidationException("Blazing Bubble probability not specified");
		}
		if(frameBreak == null) {
			throw new ConfigValidationException("Framebreak not specified");
		}
		if(pushCount == null) {
			throw new ConfigValidationException("Pushcount not specified");
		}
	}

	public CannonConfiguration getCannonConfiguration() {
		return new CannonConfiguration(cannonRotationUpdateFrequencySeconds, cannonFireForce, cannonPanningSpeed);
	}

	public static Config getInstance() {
		if(config == null) {
			config = new Config();
		}
		return config;
	}
}
